//
//  SDNestedTableViewController.h
//  SDNestedTablesExample
//
//  Created by Daniele De Matteis on 21/05/2012.
//  Copyright (c) 2012 Daniele De Matteis. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "SDGroupCell2.h"
#import "SDSubCell2.h"

@protocol SDNestedTableDelegate2<NSObject>

- (void) mainTable:(UITableView *)mainTable itemDidChange:(SDGroupCell2 *)item;
- (void) item:(SDGroupCell2 *)item subItemDidChange:(SDSubCell2 *)subItem;

@end

@interface SDNestedTableViewController2 : UITableViewController<SDNestedTableDelegate2> {
	NSMutableDictionary *expandedIndexes;
    NSIndexPath *lastIndexPath;
}

- (void) mainItemDidChange: (SDGroupCell2 *)item forTap:(BOOL)tapped;
- (void) mainItem:(SDGroupCell2 *)item subItemDidChange: (SDSubCell2 *)subItem forTap:(BOOL)tapped;

#pragma mark - To be implemented in subclasses

- (NSInteger) mainTable:(UITableView *)mainTable numberOfItemsInSection:(NSInteger)section;
- (NSInteger) mainTable:(UITableView *)mainTable numberOfSubItemsforItem:(SDGroupCell2 *)item atIndexPath:(NSIndexPath *)indexPath;

- (SDGroupCell2 *) mainTable:(UITableView *)mainTable setItem:(SDGroupCell2 *)item forRowAtIndexPath:(NSIndexPath *)indexPath;
- (SDSubCell2 *) item:(SDGroupCell2 *)item setSubItem:(SDSubCell2 *)subItem forRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString *) nibNameForMainCell;

#pragma mark - Internal

@property (assign) int mainItemsAmt;
@property (strong) NSMutableDictionary *subItemsAmt;
@property (assign) id<SDNestedTableDelegate2> delegate;

@property (assign) IBOutlet SDGroupCell2 *groupCell;

- (void) collapsableButtonTapped: (UIControl *)button withEvent: (UIEvent *)event;
- (void) groupCell:(SDGroupCell2 *)cell didSelectSubCell:(SDSubCell2 *)subCell withIndexPath: (NSIndexPath *)indexPath andWithTap:(BOOL)tapped;

@end
